package com.leo.nio.filechannel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author du
 */
public class NioFileChannelTransferFrom {

    public static void main(String[] args) throws IOException {

        // 输入流读取文件
        FileInputStream inputStream = new FileInputStream("d:\\1.jpg");
        FileChannel sourceChannel = inputStream.getChannel();

        // 输出流写入文件
        FileOutputStream outputStream = new FileOutputStream("d:\\2.jpg");
        FileChannel destChannel = outputStream.getChannel();

        // 通道拷贝数据
        destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());

        // 关闭流
        inputStream.close();
        destChannel.close();
    }
}
